TsoukMon Viewer: Pokemon, Moves, and Abilities
Pokemon
Moves
Abilities
# Pokemon Summary
poke_filter <- filter(poke_db, Name == "Geodude")
#poke_filter
#################
# Base Stats
poke_filter_base <- select(poke_filter, Name, Types, HP, ATTACK, DEFENSE, SPECIAL_ATTACK, SPECIAL_DEFENSE, SPEED, Abilities, HiddenAbilities, Evolutions)
selected_poke_stats <- gather(poke_filter_base, key = "Pokemon_ID", value = "Stat")
colnames(selected_poke_stats) <- c("Stat","Value")
#################
# Ability
ability_filter <- select(poke_filter,Pokemon_ID,Abilities,HiddenAbilities)
ability_filter <- ability_filter %>% separate(Abilities, into = c("Ability1", "Ability2"), sep = ",", fill = "right")
ability_filter <- ability_filter %>% separate(HiddenAbilities, into = c("HiddenAbility1","HiddenAbility2","HiddenAbility3"), sep = ",", fill = "right")
ability_end <- gather(ability_filter, key="Pokemon_ID", value = "Ability", na.rm = TRUE)
ability_list <- left_join(ability_end, ability_db, by = c("Ability" = "Ability_ID"))
colnames(ability_list) <- c(" ","Ability_ID","Ability","Description","Flags")
selected_poke_abilities <- select(ability_list, Ability, Description, " ")
#ability_summary
#################
# Selected Pokemon Moves
# Split learned moves into vector
elements <- unlist(strsplit(poke_filter$Moves, ","))
# Extract levels and moves (odd vs even indexed values)
levels <- as.integer(elements[c(TRUE, FALSE)]) # Odd-indexed values
moves <- elements[c(FALSE, TRUE)] # Even-indexed values
# Create the data frame
moves_df <- data.frame(Level = levels, Move = moves, stringsAsFactors = FALSE)
selected_poke_moves <- left_join(moves_df, move_db, by = c("Move" = "Move_ID"))[,1:8]
# Pokemon Summary
#poke_filter <- filter(poke_db, Name == "Geodude")
poke_filter <- poke_db
###################
#### Base Stats ###
###################
poke_filter_base <- select(poke_filter, Pokemon_ID, Name, FormName, Types, HP, ATTACK, DEFENSE, SPECIAL_ATTACK, SPECIAL_DEFENSE, SPEED, Abilities, HiddenAbilities, Evolutions, Moves)
selected_poke_stats <- pivot_longer(poke_filter_base
,cols = c("Types","HP","ATTACK","DEFENSE","SPECIAL_ATTACK","SPECIAL_DEFENSE","SPEED","Moves","Evolutions","Abilities","HiddenAbilities")
,names_to = "Stat"
,values_to = "Value"
)
selected_poke_stats <- filter(selected_poke_stats,! Stat %in% c("Moves", "Abilities", "HiddenAbilities", "Evolutions"))
names(selected_poke_stats)[names(selected_poke_stats) == 'Name'] <- 'Pokemon'
#colnames(selected_poke_stats) <- c("Stat","Value")
#selected_poke_stats
###################
##### Ability ####
##################
ability_filter <- select(poke_filter,Pokemon_ID,Name,FormName,Abilities,HiddenAbilities)
ability_filter <- ability_filter %>% separate(Abilities, into = c("Ability1", "Ability2"), sep = ",", fill = "right")
ability_filter <- ability_filter %>% separate(HiddenAbilities, into = c("HiddenAbility1","HiddenAbility2","HiddenAbility3"), sep = ",", fill = "right")
#ability_end <- gather(ability_filter, key="Pokemon_ID", value = "Ability", na.rm = TRUE)
ability_end <- pivot_longer(ability_filter
,cols = c("Ability1","Ability2","HiddenAbility1","HiddenAbility2","HiddenAbility3")
,names_to = "Type"
,values_to = "Ability")
ability_list <- filter(left_join(ability_end, ability_db, by = c("Ability" = "Ability_ID")), !is.na(Ability))
colnames(ability_list) <- c("Pokemon_ID","Pokemon","FormName"," ","Ability","Name","Description","Flags")
selected_poke_abilities <- select(ability_list, Pokemon, Ability, Description, " ")
#ability_summary
###############################
### Selected Pokemon Moves ###
##############################
poke_filter_NA_RM <- filter(poke_filter, !is.na(Moves))
poke_filter_moves <- select(poke_filter_NA_RM, Pokemon_ID, Name, Moves)
# Step 1: Split the Moves column into separate rows based on commas
# Transform the data
poke_move_summary <- poke_filter_NA_RM %>%
# Separate each value in the Moves column into individual rows
separate_rows(Moves, sep = ",") %>%
# Add a column with row numbers to distinguish between level and move names
group_by(Name) %>%
mutate(row_id = 2 * ceiling(row_number() / 2)) %>%
# Use modulo to identify odd rows as move levels and even rows as move names
mutate(category = ifelse(row_number() %% 2 == 1, "Move_Level", "Move_Name")) %>%
# Pivot data so that Move_Level and Move_Name are in separate columns
pivot_wider(names_from = category, values_from = Moves) %>%
# Remove the row_id column and ungroup
select(-row_id) %>%
ungroup() %>%
# Convert the Move_Level column to numeric (since it's character after splitting)
mutate(Move_Level = as.integer(Move_Level)) %>%
# Select relevant columns
select(Pokemon_ID, Name, Move_Level, Move_Name)
# Remove duplicates
poke_move_summary <- unique(poke_move_summary)
selected_poke_moves <- left_join(poke_move_summary, move_db, by = c("Move_Name" = "Move_ID"))[,1:11]
colnames(selected_poke_moves) <- c("Pokemon_ID","Pokemon","Level","Move_ID","Name","Type","Category","Power","Accuracy","PP","Target")
filter(selected_poke_moves, Pokemon == "Tsoukinator")
filter(poke_move_summary, Name == "Abomasnow")
filter(poke_move_summary, Name == "Tsoukinator")
filter(poke_filter_NA_RM, Name == "Tsoukinator")
test <- data.frame(Name = poke_filter_NA_RM$Name, Moves = poke_filter_NA_RM$Moves)
tidy_moves <- test %>%
# Separate each value in the Moves column into individual rows
separate_rows(Moves, sep = ",") %>%
# Add a column with row numbers to distinguish between level and move names
group_by(Name) %>%
mutate(row_id = 2 * ceiling(row_number()/2)) %>%
# Use modulo to identify the odd rows as move levels and even rows as move names
mutate(category = ifelse(row_id %% 2 == 1, "Move_Level", "Move_Name")) %>%
# Pivot data so that Move_Level and Move_Name are in separate columns
pivot_wider(names_from = category, values_from = Moves) %>%
# Remove the row_id column and ungroup
#select(-row_id) %>%
ungroup()
tsouk <- filter(tidy_moves, Name == "Tsoukinator")
#2 * round(df$a/2)
t <- unlist(tsouk$Move_Name[[1]])
t
# Assuming you've already transformed the data as described
tidy_moves <- poke_filter_NA_RM %>%
# Separate each value in the Moves column into individual rows
separate_rows(Moves, sep = ",") %>%
# Add a column with row numbers to distinguish between level and move names
group_by(Name) %>%
mutate(row_id = 2 * ceiling(row_number() / 2)) %>%
# Use modulo to identify odd rows as move levels and even rows as move names
mutate(category = ifelse(row_number() %% 2 == 1, "Move_Level", "Move_Name")) %>%
# Pivot data so that Move_Level and Move_Name are in separate columns
pivot_wider(names_from = category, values_from = Moves) %>%
# Remove the row_id column and ungroup
select(-row_id) %>%
ungroup() %>%
# Convert the Move_Level column to numeric (since it's character after splitting)
mutate(Move_Level = as.integer(Move_Level)) %>%
# Select relevant columns
select(Pokemon_ID, Name, Move_Level, Move_Name)
# View the result
print(tidy_moves)
filter(tidy_moves, Name == "Tsoukinator")
tsoukmon_pkmn <- select(filter(readxl::read_excel("PokeDB.xlsx", sheet = "PkmnStats"), is.na(`Pokedex Number`)), Name)
tsoukmon_pkmn$Pokemon_ID <- toupper(gsub(" ","",tsoukmon_pkmn$Name))
tsoukmon_moves <- select(filter(readxl::read_excel("PokeDB.xlsx", sheet = "Moves")), Name)
tsoukmon_moves$Move_ID <- toupper(gsub(" ","",tsoukmon_moves$Name))
tsoukmon_abilities <- select(filter(readxl::read_excel("PokeDB.xlsx", sheet = "Abilities")), Name)
tsoukmon_abilities$Ability_ID <- toupper(gsub(" ","",tsoukmon_abilities$Name))
test <- filter(poke_db_short, (Name == "Tsoukinator" | Name == "Pikachu"))
test_join <- left_join(test, tsoukmon_pkmn, by = c("Name" = "Name"))
test_join
test$TsoukMon_OG <- test$Name %in% tsoukmon_pkmn$Name
library(plotly)
library(RColorBrewer)
palette_blues <- colorRampPalette(colors =c("#F34444","#FF7F0F","#FFDD57","#A0E515","#00C2B8"))
tsouk_colours <- c("#F34444","#FF7F0F","#FFDD57","#A0E515","#00C2B8")
tsouk_palette <- brewer.pal(n=5, name="Dark2")
tsouk_palette <- tsouk_palette
#val
foodbaby <- filter(selected_poke_stats, Pokemon == "FoodBaby" & Stat != "Types")
foodbaby$Stat <- factor(foodbaby$Stat, levels = c("HP", "ATTACK", "DEFENSE", "SPECIAL_ATTACK", "SPECIAL_DEFENSE", "SPEED"))
foodbaby$Value <- as.numeric(foodbaby$Value)
fig <- plot_ly(x = foodbaby$Value, y = foodbaby$Stat, type = 'bar', orientation = 'h',
marker = list(color = brewer.pal(6, "Dark2")),
text = foodbaby$Value, # Show the Value as text
textposition = 'auto') %>%
layout(
xaxis = list(range = c(0, 200),showticklabels = FALSE),
yaxis = list(autorange = "reversed"
),
height = 300
)
Warning: Specifying width/height in layout() is now deprecated.
Please specify in ggplotly() or plot_ly()
fig
#brewer.pal(6, "Dark2")
library(plotly)
# Your custom color palette
tsouk_colours <- c("#F34444", "#FF7F0F", "#FFDD57", "#A0E515", "#00C2B8")
# Define breaks and corresponding colors
breaks <- c(-1, 40, 60, 90, 120, 200)
colors <- tsouk_colours
# Function to assign colors based on breaks
assign_color <- function(value) {
cut(value, breaks = breaks, labels = colors, include.lowest = TRUE)
}
# Apply the color assignment function
value_colors <- assign_color(foodbaby$Value)
# Create the Plotly figure
fig <- plot_ly(x = foodbaby$Value, y = foodbaby$Stat, type = 'bar', orientation = 'h',
marker = list(color = value_colors), # Use discrete colors
text = foodbaby$Value, # Show the Value as text
textposition = 'auto') %>%
layout(
xaxis = list(range = c(0, 200), showticklabels = FALSE),
yaxis = list(autorange = "reversed"),
height = 300
)
Warning: Specifying width/height in layout() is now deprecated.
Please specify in ggplotly() or plot_ly()
fig
NA
NA
# Load necessary library
library(plotly)
library(grDevices)
# Original color palette
tsouk_colours <- c("#F34444", "#FF7F0F", "#FFDD57", "#A0E515", "#00C2B8")
# Function to create a color scale with intermediate colors
create_color_scale <- function(colors, n) {
# Interpolate colors
color_scale <- colorRampPalette(colors)(n)
return(color_scale)
}
# Create a new color scale with 10 colors
expanded_colours <- create_color_scale(tsouk_colours, 8)
# Define breaks (one more than the number of colors)
breaks <- c(-1, 0, 20, 40, 60, 80, 100, 150, 200)
colors <- expanded_colours # Use the expanded color palette
# Function to assign colors based on breaks
assign_color <- function(value) {
cut(value, breaks = breaks, labels = colors, include.lowest = TRUE)
}
base_stats <- filter(selected_poke_stats, Pokemon == "Haydos" & Stat != "Types")
base_stats$Stat <- factor(base_stats$Stat, levels = c("HP", "ATTACK", "DEFENSE", "SPECIAL_ATTACK", "SPECIAL_DEFENSE", "SPEED"))
base_stats$Value <- as.numeric(base_stats$Value)
# Apply the color assignment function
value_colors <- assign_color(base_stats$Value)
# Create the Plotly figure
fig <- plot_ly(x = base_stats$Value, y = base_stats$Stat, type = 'bar', orientation = 'h',
marker = list(color = value_colors), # Use discrete colors
text = base_stats$Value, # Show the Value as text
textposition = 'auto') %>%
layout(
xaxis = list(range = c(0, 200), showticklabels = FALSE, showgrid = FALSE),
yaxis = list(autorange = "reversed"),
height = 270,
plot_bgcolor = "transparent",
paper_bgcolor = "transparent"
)
Warning: Specifying width/height in layout() is now deprecated.
Please specify in ggplotly() or plot_ly()
fig
NA